﻿using Sunny.UI;
using System;
using System.Threading;
using static Assistant.Controllers.PrintModel;

namespace Assistant.Report.Preview
{
    public partial class FormStartPreview : UIForm
    {
        private PrintAction action;
        Thread thread;

        public FormStartPreview(PrintAction printAction)
        {
            InitializeComponent();
            action = printAction;

            StartPreview();
        }

        public void StartPreview()
        {
            thread = new Thread(new ThreadStart(PreviewDialog));
            thread.SetApartmentState(ApartmentState.STA); //重点
            thread.Start();
            
        }

        private void PreviewDialog()
        {
            FormPreview formPreview = new FormPreview();
            formPreview.ReceivingPrintData(action);
            formPreview.ShowDialog();
        }

        private void FormStartPreview_Load(object sender, EventArgs e)
        {
            if(thread!= null)
            {
                this.Close();
            }
            
        }
    }
}
